<template>
	<view>
    <poster></poster>
		<goods-list @goodsItemClick="goGoodsDetail" :goods="goods"></goods-list>
		<view class="flagOver">没有更多数据...</view>
	</view>
</template>

<script>
	import goodsList from '../../common/goods-list/goods-list.vue'
  import Poster from "./poster.vue";
	export default {
		components:{goodsList, Poster},
		data() {
			return {
				flag:false,
				goods:[],
				pagenum:1,
        share:{
          title:'detail',
          path: "/pages/index/index?source=detailPage&sence=",
          imageUrl:'',
          desc:'',
          content:''
        },
			}
		},
		onLoad() {
			this.getHotGoods()
		},
    //三个点的分享给好友
    onShareAppMessage(res) {
      return {
        title:this.share.title,
        path:this.share.path,
        success(res){
          uni.showToast({
            title:'分享成功'
          })
        },
        fail(res){
          uni.showToast({
            title:'分享失败',
            icon:'none'
          })
        }
      }
    },
		onReachBottom() {
			if(this.goods.length<20*this.pagenum) return this.flag = true;
			
			this.pagenum++
			this.getHotGoods()
		},
		onPullDownRefresh() {
			this.pagenum=1;
			this.flag=false;
			this.goods=[]
			this.getHotGoods(()=>{
				uni.stopPullDownRefresh()
			})
		},
		methods: {
      tiaozhuan(){
           uni.navigateTo({
            url:"/pages/index/index?source=detailPage&sence=",
            })
      },
			// 获取商品列表数据
			async getHotGoods (callback) {
				const res = await this.http({
					url: '/api/public/v1/goods/search?pagenum='+this.pagenum
				})
				this.goods = [this.goods,...res.data.message.goods]
				callback?callback():null
			},
			// 导航到商品详情页
			goGoodsDetail (id) {
				uni.navigateTo({
					url: '../goodsDetail/goodsDetail?goods_id='+id
				})
			}
		}
	}
</script>

<style class="goods">
.flagOver{
	width: 100%;
	height: 50px;
	line-height: 50px;
	text-align: center;
}
</style>
